using System;
using System.Linq.Expressions;
using HeadspringExample.UI.Helpers;
using NUnit.Framework;
using WatiN.Core;

namespace HeadspringExample.UITests
{
    public class FluentPage<TModel>
    {
        private readonly IE _browser;

        public FluentPage(IE browser)
        {
            _browser = browser;
        }

        public FluentPage<TModel> AssertPageContains(
            Expression<Func<TModel, object>> modelExpr,
            string expected)
        {
            var spanId = UINameHelper.BuildIdFrom(modelExpr);

            var span = _browser.Span(Find.ById(spanId));

            Assert.AreEqual(expected, span.Text);

            return this;
        }

        public FluentPage<TModel> AssertPageContainsLink(
            Expression<Func<TModel, object>> modelExpr,
            string expected)
        {
            var spanId = UINameHelper.BuildIdFrom(modelExpr);

            var span = _browser.Span(Find.ById(spanId));

            Assert.AreEqual(expected, span.Text);

            return this;
        }
    }
}